/*
 *  CETreeListItem.h
 *  LID Library
 *
 *  Created by Alexander Trutchenko on 09/11/11.
 *  Copyright 2011 League of Independent Developers. All rights reserved.
 *
 */

#ifndef __CE_TreeListItem_h__
#define __CE_TreeListItem_h__

#include "cocos2dx_extentions/controls/CEListItem.h"

#include <vector>

namespace cocosext {


/////////////////////////////////////////////////////
//
/** CEListItemInfo 
* 
*/
/////////////////////////////////////////////////////

struct CETreeListItemInfo : public CEListItemInfo
{
	CEListItems subitems;

public:
	CETreeListItemInfo()  {;}
	CETreeListItemInfo(float marginLeft_, float marginRight_, bool isAutoResizable_): CEListItemInfo(marginLeft_, marginRight_, isAutoResizable_) {;}
};


/////////////////////////////////////////////////////
//
/** CETreeListItem 
* Item of vertical list view which contains subitems
*/
/////////////////////////////////////////////////////

class CETreeListItem : public CEListItem
{
protected:
	CEListItems _subitemsVec;
	cocos2d::CCArray* _subitems;
	bool _isExpanded;

protected:
	CETreeListItem(const CETreeListItemInfo& info): CEListItem(info), _isExpanded(false) 
	{
		_subitemsVec = info.subitems;
		_subitems = cocos2d::CCArray::arrayWithCapacity(info.subitems.size());
		_subitems->retain();
		for (CEListItems::const_iterator it = info.subitems.begin(); it != info.subitems.end(); ++it)
			_subitems->addObject(*it);
	}

public:
    virtual ~CETreeListItem()
	{
		CC_SAFE_RELEASE(_subitems);
	}

    /* Static constructors */
    /** creates a menu item with a normal, selected and disabled image*/
    static CETreeListItem* itemFromNormalSprite(const CETreeListItemInfo& info, cocos2d::CCNode* normalSprite, cocos2d::CCNode* selectedSprite, cocos2d::CCNode* disabledSprite = NULL);

public:
    /** initializes a menu item with a normal, selected  and disabled image with target/selector */
    bool initFromNormalSprite(cocos2d::CCNode* normalSprite, cocos2d::CCNode* selectedSprite, cocos2d::CCNode* disabledSprite);


public:
	//Cocos2dx interface
	virtual void activate();

	//Main interface
	virtual void revertExpandState();

protected:
	virtual void onAfterAdd(CEVerticalListView* list);
	virtual void onBeforeRemove();

}; //CETreeListItem

/////////////////////////////////////////////////////
//
/** CETreeListItemSupplement 
* 
*/
/////////////////////////////////////////////////////

class CETreeListItemSupplement : public CEListItem
{
protected:
	CETreeListItem* _master;

protected:
	CETreeListItemSupplement(const CEListItemInfo& info, CETreeListItem* master): CEListItem(info), _master(master) {;}

public:
	virtual ~CETreeListItemSupplement() {;}

    /* Static constructors */
    /** creates a menu item with a normal, selected and disabled image*/
    static CETreeListItemSupplement* itemFromNormalSprite(const CEListItemInfo& info, CETreeListItem* master, cocos2d::CCNode* normalSprite, cocos2d::CCNode* selectedSprite, cocos2d::CCNode* disabledSprite = NULL);

public:
    /** initializes a menu item with a normal, selected  and disabled image with target/selector */
    bool initFromNormalSprite(cocos2d::CCNode* normalSprite, cocos2d::CCNode* selectedSprite, cocos2d::CCNode* disabledSprite);


public:
	//Cocos2dx interface
	virtual void activate();

}; //CETreeListItemSupplement

}; // end namespace cocosext

#endif // __CE_TreeListItem_h__
